<?php
namespace Tbf\Component\Encode\Tests;
use Tbf\Bundle\TestBundle\TestSuite\TbfTestCase;
use Tbf\Component\Encode\EncodeFunction;

class EncodeTest extends TbfTestCase{
    function test1(){
        $test_table = array(
            'a'=>'YQ',
            'aa'=>'YWE',
            'aaa'=>'YWFh',
            'aaaa'=>'YWFhYQ',
            'any carnal pleasure.'=>'YW55IGNhcm5hbCBwbGVhc3VyZS4',
            "\xfb"=>'-w',
            "\xfb\xff"=>'-_8',
        );
        foreach($test_table as $origin=>$encoded){
            $this->assertEquals($encoded,EncodeFunction::base64urlEncode($origin));
            $this->assertEquals($origin,EncodeFunction::base64urlDecode($encoded));
        }
        $this->assertEquals(false,EncodeFunction::base64urlDecode('哈哈'));
        $this->assertEquals(false,EncodeFunction::base64urlDecode(6));
        $this->assertEquals(false,EncodeFunction::base64urlDecode(array()));
        $this->assertEquals('',EncodeFunction::base64urlDecode(''));
        $this->assertEquals('',EncodeFunction::base64urlEncode(''));
    }
}